package com.mojo.jvm.jvm_01_asm;


import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.ClassVisitor;
import jdk.internal.org.objectweb.asm.ClassWriter;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 使用ASM字节码增强技术实现简单的AOP
 *
 * @author <a href="mailto:mojo_jj@163.com">Mojo</a>
 */
public class ASMTest {
    public static void main(String[] args) throws IOException {
        //读取
        ClassReader classReader = new ClassReader("com/mojo/jvm/jvm_01_javassit/Base");
        ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        //处理
        ClassVisitor classVisitor = new MyClassVisitor(classWriter);
        classReader.accept(classVisitor, ClassReader.SKIP_DEBUG);
        byte[] data = classWriter.toByteArray();
        //输出
        File f = new File("mojo-jvm/target/classes/com/mojo/jvm/javassit/Base.class");
        FileOutputStream out = new FileOutputStream(f);
        out.write(data);
        out.close();
        System.out.println("now generator cc success!!!!!");
    }
}
